﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sunboxsoft.WinForm;
using Sunboxsoft.ASMS.Client.UI.Properties;
using WebRef = Sunboxsoft.ASMS.Client.Domain.WebRef;
using Service = Sunboxsoft.ASMS.Client.Domain.Service;
using Sunboxsoft.Common;
namespace Sunboxsoft.ASMS.Client.UI.Show
{
    /// <summary>
    /// 查看库房详细信息
    /// </summary>
    public partial class ShowWareHouseDetailView : UserControl, IView
    {
        WebRef.VWarehouse _vWarehouse = null;
        Promise _promise = new Promise();
        public ShowWareHouseDetailView()
        {
            InitializeComponent();
        }
        public ShowWareHouseDetailView(WebRef.VWarehouse vWarehouse)
            : this()
        {
            this._vWarehouse = vWarehouse;
        }

        #region IView 成员

        public void RegisterAction(ActionNodeCollection collection)
        {
            collection.AddAction(new ActionNode("close", Resources.isDelete, "关闭", btnClose_Click));
        }

        public void Active(ViewActiveArgs args)
        {
            _promise
            .Then(() =>
            {
                this.BeginInvoke(new Action(() =>
                {
                    GetVWareHouse();
                    _promise.Resolve();
                }));
            })
            .Run();
        }

        public void Resume(ViewResumeArgs args)
        {
        }

        public ViewHeader GetHeader()
        {
            return new ViewHeader("查看库房信息");
        }
        #endregion

        #region Mehtod
        /// <summary>
        /// 获取库房详细信息
        /// </summary>
        private void GetVWareHouse()
        {
            if (_vWarehouse != null)
            {
                this.ctlEditCode.Text = _vWarehouse.Code;
                this.ctlEditName.Text = _vWarehouse.Name;
                this.ctlEditCountryName.Text = _vWarehouse.CountryName;
                this.ctlEditProvinceName.Text = _vWarehouse.ProvinceName;
                this.ctlEditCityName.Text = _vWarehouse.CityName;
                this.ctlEditDistrictName.Text = _vWarehouse.DistrictName;
                this.ctlEditAddress.Text = _vWarehouse.Address;
                this.ctlEditContactName.Text = _vWarehouse.ContactName;
                this.ctlEditTel.Text = _vWarehouse.ContactTelephone;
                this.ctlEditDes.Text = _vWarehouse.Description;
            }
        }
        #endregion

        #region Action
        /// <summary>
        /// 关闭
        /// </summary>
        private void btnClose_Click(object sender, object e)
        {
            UIContext.Current.ViewManager.CloseView(false, null);
        }
        #endregion
    }
}
